from models import inception_v3 as gnet
import numpy as np
import random,os

WIDTH = 40
HEIGHT = 120
LR = 1e-3
EPOCHS = 30
model_name = 'gl_model_v2'

model = gnet(WIDTH,HEIGHT,3,LR,output=7,model_name=model_name)

os.system('cls')
input('ready to train')
train_data = np.load('train_data_v2.npy')
print('load data sucessfully.')

random.shuffle(train_data)
#reshape data

data_x = []
data_x = np.array(data_x)
data_y = []
data_y = np.array(data_y)

data_x = np.array([i[0] for i in train_data]).reshape(-1,WIDTH,HEIGHT,3)
data_y = np.array([a[1] for a in train_data])


#train test
a = int(len(data_x)*0.75)
test_x = data_x[a:]
test_y = data_y[a:]
train_x = data_x[:a]
train_y = data_y[:a]


input('train:'+str(len(train_x))+"\n"+'test:'+str(len(test_x)))

model.load(model_name)

times = 1

for e in range(EPOCHS-1):
    model.fit({'input':train_x},{'targets':train_y},n_epoch=1,validation_set=({'input':test_x},{'targets':test_y}),snapshot_step=2500
              ,show_metric=True,run_id=model_name)
    times += 1
    if times == 5:
        model.save(model_name)
        print('------save the model---------')
        times = 1